package sqlsession;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2020-01-08 16:16
* @notify 
* @version 1.0
*/

import builder.XMLConfigBuilder;
import mapping.Configuration;
import org.dom4j.Document;
import org.dom4j.Element;
import sqlsession.impl.DefaultSqlSessionFactory;
import utils.DocumentUtil;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public static SqlSessionFactory build(InputStream inputStream)throws Exception{

        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Document document = DocumentUtil.readDocument(inputStream);
        Element rootElement = document.getRootElement();
        Configuration configuration = xmlConfigBuilder.parse(rootElement);
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }


}
